from django.db import models
from ckeditor.fields import RichTextField
# Create your models here.


class Info(models.Model):
    car_username = models.ForeignKey('user.Info', on_delete=models.CASCADE, verbose_name='车主用户名')  # 车主用户名
    car_title = models.CharField(max_length=50,verbose_name='车辆标题（建议写入型号）')     # 车辆标题
    keyword = models.CharField(max_length=200,verbose_name='关键字（标签）')   # 关键字
    car_price = models.DecimalField(max_digits=8,decimal_places=2,verbose_name='汽车原价（2位小数）')        # 车 原价
    car_buy_price = models.DecimalField(max_digits=8,decimal_places=2,verbose_name='汽车现价（2位小数）')     # 车 现价
    car_brand = models.ForeignKey('Brand',on_delete=models.CASCADE,verbose_name='车品牌')  # 车品牌
    car_type = models.ForeignKey('Type',on_delete=models.CASCADE,verbose_name='车类型')   # 车类型
    car_color = models.ForeignKey('Color',on_delete=models.CASCADE,verbose_name='车颜色')   # 车颜色
    car_year = models.IntegerField(verbose_name='车辆购买年份')    # 车辆购买年份
    car_mainpic = models.ImageField(upload_to='cars/')  # 车辆主图
    car_pics = models.ImageField(upload_to='cars/')      # 车辆详情图片
    car_details = RichTextField(blank=True,null=True,verbose_name='车辆详情') # 车辆详情
    car_km = models.DecimalField(max_digits=8,decimal_places=2,verbose_name='车辆行使里程')  # 车辆行使里程
    car_output = models.DecimalField(max_digits=2,decimal_places=1,verbose_name='车辆排量') # 车辆排量
    car_output_standard = models.CharField(max_length=8,verbose_name='车辆排量标准')  # 车辆排量标准
    car_address = models.ForeignKey('common.Area', on_delete=models.CASCADE, verbose_name='上牌地')   # 上牌地
    car_transfer = models.IntegerField(verbose_name='过户次数')   # 过户次数
    car_yearcheck = models.DateField(verbose_name='年检到期')   # 年检到期
    car_secure = models.DateField(verbose_name='保险到期')   # 保险到期
    is_sell = models.IntegerField(verbose_name='是否卖掉')   # 是否卖掉
    is_delete = models.IntegerField(verbose_name='是否删除')   # 是否删除
    add_time = models.DateTimeField(verbose_name='添加时间')  # 添加时间
    update_time = models.DateTimeField(verbose_name='修改时间')  # 修改时间

    class Meta:
        db_table = 'tb_car_info'
        verbose_name = '车辆信息'
        verbose_name_plural = verbose_name


class Brand(models.Model):
    brand_name = models.CharField(max_length=8,verbose_name='品牌名字')     # 品牌名字
    sort_by = models.IntegerField(verbose_name='品牌序号')
    class Meta:
        db_table = 'tb_car_brand'
        verbose_name = '车辆品牌'
        verbose_name_plural = verbose_name

class Type(models.Model):
    type_name = models.CharField(max_length=8,verbose_name='车类型名')   # 车类型名
    sort_by = models.IntegerField(verbose_name='类型序号')

    class Meta:
        db_table = 'tb_car_type'
        verbose_name = '车辆类型'
        verbose_name_plural = verbose_name

class Color(models.Model):
    color_name = models.CharField(max_length=8,verbose_name='车颜色')    # 车颜色
    sort_by = models.IntegerField(verbose_name='颜色序号')

    class Meta:
        db_table = 'tb_car_color'
        verbose_name = '车辆颜色'
        verbose_name_plural = verbose_name

